package com.fenghongzhang.day010;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    private ContentResolver contentResolver;
    private Uri parse;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //解析者.
         contentResolver = getContentResolver();

        //对比网址
         parse = Uri.parse("content://com.fenghongzhang");
    }

    public void select(View view) {


        Cursor cursor = contentResolver.query(parse, null, null, null, null);
        if(cursor != null){
            while(cursor.moveToNext()){
                String name = cursor.getString(cursor.getColumnIndex("name"));
                Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
            }

            cursor.close();
        }

    }

    public void insert(View view) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("name","大学明");
        contentResolver.insert(parse,contentValues);
    }

    public void delete(View view) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("name","大学明");
        contentResolver.delete(parse,"name = ?",new String[]{"大学明"});
    }

    public void update(View view) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("name","大学明");
        contentResolver.update(parse,contentValues,"name= ?",new String[]{"李白"});
    }
}
